package org.mzx.shortLink.adminn.remoteApi.Api;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mzx.shortLink.adminn.remoteApi.dto.Request.ShortLinkGroupStatsAccessRecordReqDTO;
import org.mzx.shortLink.adminn.remoteApi.dto.Request.ShortLinkGroupStatsReqDTO;
import org.mzx.shortLink.adminn.remoteApi.dto.Request.ShortLinkStatsAccessRecordReqDTO;
import org.mzx.shortLink.adminn.remoteApi.dto.Request.ShortLinkStatsReqDTO;
import org.mzx.shortLink.adminn.remoteApi.dto.Response.ShortLinkStatsAccessRecordRespDTO;
import org.mzx.shortLink.adminn.remoteApi.dto.Response.ShortLinkStatsRespDTO;
import org.mzx.shortLink.starter.convention.Result.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.HashMap;
@Component
public class TlinkStatsApi {
    /**
     * 访问单个短链接指定时间内监控数据
     */

    public Result<ShortLinkStatsRespDTO> shortLinkStats(@RequestBody ShortLinkStatsReqDTO requestParam) {
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("gid",requestParam.getGid());
        paramMap.put("fullShortUrl",requestParam.getFullShortUrl());
        paramMap.put("endDate",requestParam.getEndDate());
        paramMap.put("startDate",requestParam.getStartDate());
        paramMap.put("enableStatus",requestParam.getEnableStatus());
        String result = HttpUtil.get("http://localhost:8001/api/short-link/v1/stats",paramMap);
        return JSONObject.parseObject(result, new TypeReference<>() {
        });
    }
    /**
     * 访问分组短链接指定时间内监控数据
     */

    public Result<ShortLinkStatsRespDTO> groupShortLinkStats(@RequestBody ShortLinkGroupStatsReqDTO requestParam) {
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("gid",requestParam.getGid());
        paramMap.put("endDate",requestParam.getEndDate());
        paramMap.put("startDate",requestParam.getStartDate());
        String result = HttpUtil.get("http://localhost:8001/api/short-link/v1/stats/group",paramMap);
        return JSONObject.parseObject(result, new TypeReference<>() {
        });
    }

    /**
     * 分页查询单个短链接单位时间内访问记录
     */

    public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> shortLinkStatsAccessRecord(@RequestBody ShortLinkStatsAccessRecordReqDTO requestParam) {
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("gid",requestParam.getGid());
        paramMap.put("fullShortUrl",requestParam.getFullShortUrl());
        paramMap.put("endDate",requestParam.getEndDate());
        paramMap.put("startDate",requestParam.getStartDate());
        paramMap.put("enableStatus",requestParam.getEnableStatus());
        String result = HttpUtil.get("http://localhost:8001/api/short-link/v1/stats/access-record",paramMap);
        return JSONObject.parseObject(result, new TypeReference<>() {
        });
    }
    /**
     * 访问分组短链接指定时间内访问记录监控数据
     */

    public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> groupShortLinkStatsAccessRecord(@RequestBody ShortLinkGroupStatsAccessRecordReqDTO requestParam) {
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("gid",requestParam.getGid());
        paramMap.put("endDate",requestParam.getEndDate());
        paramMap.put("startDate",requestParam.getStartDate());
        String result = HttpUtil.get("http://localhost:8001/api/short-link/v1/stats/access-record/group",paramMap);
        return JSONObject.parseObject(result, new TypeReference<>() {
        });
    }
}
